<?php

namespace App\Http\Controllers\Notes;

use App\Http\Controllers\Controller;
use App\Services\Notes\NotesServices;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class NotesController extends Controller
{
    /**
     * 获取分类.
     *
     * @param NotesServices $services
     * @return JsonResponse
     */
    public function notesClassify(NotesServices $services): JsonResponse
    {
        $res = $services->notesClassify();

        return $this->responseSuccess($res);
    }

    /**
     * 添加笔记.
     *
     * @param Request $request
     * @param NotesServices $services
     * @return JsonResponse
     */
    public function addNotes(Request $request, NotesServices $services): JsonResponse
    {
        $res = $services->addNotes($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess();
    }

    /**
     * 列表.
     *
     * @param Request $request
     * @param NotesServices $services
     * @return JsonResponse
     */
    public function noteList(Request $request, NotesServices $services): JsonResponse
    {
        $res = $services->noteList($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess($res);
    }

    /**
     * 删除笔记.
     *
     * @param Request $request
     * @param NotesServices $services
     * @return JsonResponse
     */
    public function delNotes(Request $request, NotesServices $services): JsonResponse
    {
        $res = $services->delNotes($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess();
    }

    public function noteDetail(Request $request, NotesServices $services): JsonResponse
    {
        $res = $services->noteDetail($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess($res);
    }
}
